<?php

include("../utility/connection.php");
include("../model/mUser.php");
session_start();

$Nama = trim(mysql_real_escape_string($_POST["txtNama"]));
$Alamat = trim(mysql_real_escape_string($_POST["txtAlamat"]));
$Kota = trim(mysql_real_escape_string($_POST["txtKota"]));
$Propinsi = trim(mysql_real_escape_string($_POST["txtPropinsi"]));
$Negara = trim(mysql_real_escape_string($_POST["txtNegara"]));
$KodePos = trim(mysql_real_escape_string($_POST["txtKodePos"]));
$Telp= trim(mysql_real_escape_string($_POST["txtTelp"]));
$Email = trim(mysql_real_escape_string($_POST["txtEmail"]));
$LoginId = trim(mysql_real_escape_string($_POST["txtLoginId"]));
$Password = trim(mysql_real_escape_string($_POST["txtPassword"]));

$countUser = fnCountUser();
$arrResult = mysql_fetch_array($countUser);
$JmlUser = $arrResult[0];
$StsAdmin = 0;
if ($JmlUser == 0) {
    $StsAdmin = 1;
}

$results = fnInsertUser($Nama,$Alamat,$Kota,$Propinsi,$Negara,$KodePos,$Telp,$Email,$LoginId,$Password,$StsAdmin);

if ($results) {
    $message="Successfully Added! Please Login Here:";
    $_SESSION['message']=$message;
    $_SESSION['relogin']="Relogin";
    header("location: ../index.php");
} else {
    $message="Invalid query: ".mysql_error;
    $_SESSION['message']=$message;
    $_SESSION['re-register']="Re-register";
    header("location: ../ui/user/newUser.php");
}

?>
